﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using XingFuStudio.Pioneer.Applications.City.Shop;
using XingFuStudio.Pioneer.Applications.City.Entity;

namespace XingFuStudio.Pioneer.Applications.City.Element {
    /// <summary>
    /// 住宅信息实体
    /// </summary>
    public class ResidenceInfo : CityElement{
        /// <summary>
        /// 初始化元素自身数据
        /// </summary>
        /// <param name="elementObject"></param>
        public override void InitElement(Dictionary<string, object> elementObject) {
            //调用基类方法
            base.InitElement(elementObject);

            //赋值自身属性
            this.LastHarvestTime = Convert.ToDateTime(elementObject["collecttime"]);
            this.ElapseTime = Convert.ToInt32(elementObject["elapsetime"]);
        }

        /// <summary>
        /// 是否可以收获
        /// </summary>
        public bool CanHarvest(List<ShopItem> residences)  {

            switch (this.ElementId) {
                case 2063:
                case 2064:
                case 2065:
                case 2066:
                    this.ElementId = 2063;
                    break;
                case 2059:
                case 2060:
                case 2061:
                case 2062:
                    this.ElementId = 2059;
                    break;
                case 2055:
                case 2056:
                case 2057:
                case 2058:
                    this.ElementId = 2055;
                    break;
            }

            var res = residences.Where(s => s.ID == this.ElementId);

            if (res.Count() > 0) {
                ResidenceShopInfo info = res.First() as ResidenceShopInfo;
                if (info != null) {
                    if (this.ElapseTime > info.RentTimes * 60) {
                        return true;
                    }
                }
            } else {
                if (this.LastHarvestTime.AddDays(1) < DateTime.Now) {
                    return true;
                }
            }

            return false;
        }

        /// <summary>
        /// 上次收获时间
        /// </summary>
        public DateTime LastHarvestTime {
            get;
            private set;
        }

        /// <summary>
        /// 推移时间
        /// </summary>
        public int ElapseTime {
            get;
            private set;
        }

       // public bool IsUpdateElement
    }
}
